/*
 * @Author: chen haoxuan
 * @Date: 2021-06-18 21:56:53
 * @LastEditTime: 2021-06-18 22:28:24
 */
#include <iostream>
#include <math.h>
using namespace std;
class Shape
{
public:
  virtual void area() = 0;
};
// Cirele 圆形
class Circle : public Shape
{
public:
  void area();
  void get_radius();

private:
  float radius;
};
void Circle::get_radius()
{
  cout << "Please enter the radius of the circle: " << endl;
  cin >> radius;
}
void Circle::area()
{
  float area;
  area = 3.14159 * radius * radius;
  cout << "The area of circle is: " << area << endl;
}
// Rectangle 矩形
class Rectangle : public Shape
{
public:
  void area();
  void get_lengthAndwidth();

private:
  float width;
  float length;
};
void Rectangle::get_lengthAndwidth()
{
  cout << "Please enter the width and the length of rectangle: " << endl;
  cin >> width >> length;
}
void Rectangle::area()
{
  float area;
  area = width * length;
  cout << "The area of rectangle is: " << area << endl;
}

// 三角形
class Triangle : public Shape
{
public:
  void area();
  void get_sides();

private:
  float a;
  float b;
  float c;
};
void Triangle::get_sides()
{
  int m;
  cout << "Plesae enter the threes sides of Triangle: " << endl;
  cin >> a >> b >> c;
  if (a + b <= c || a + c <= b || b + c <= a) // 判断用户输入的边能否组成三角形
  {
    cout << "can not form triangle " << endl;
    cout << "enter 0 to out the program:";
    cin >> m;
    exit(m);
  }
}
void Triangle::area()
{
  float l;
  l = (a + b + c) / 2;
  float area = sqrt(l * (l - a) * (l - b) * (l - c));
  cout << "The area of Triangle is: " << area << endl;
}

int main()
{
  Circle circle1;
  circle1.get_radius();
  circle1.area();
  Rectangle re;
  re.get_lengthAndwidth();
  re.area();
  Triangle t1;
  t1.get_sides();
  t1.area();
  system("pause");
  return 0;
}